package com.example.api.service.impl;

import com.example.api.mapper.DriverMapper;
import com.example.api.model.entity.Commodity;
import com.example.api.model.entity.Driver;
import com.example.api.service.DriverService;
import com.example.api.utils.DataTimeUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service
public class DriverServiceImpl implements DriverService {

    @Resource
    private DriverMapper driverMapper;

    @Override
    public Driver insert(Driver driver) {
        if (driver.getId() == null || driver.getId().isEmpty()) {
            driver.setId(UUID.randomUUID().toString());
        }
        driver.setCreateAt(DataTimeUtil.getNowTimeString());
        driverMapper.insert(driver);
        return driver;
    }

    @Override
    public void update(Driver driver) {
        driver.setUpdateAt(DataTimeUtil.getNowTimeString());
        driverMapper.update(driver);
    }

    @Override
    public void delete(String id) {
        driverMapper.deleteById(id);
    }

    @Override
    public Driver findById(String id) {
        return driverMapper.findById(id);
    }

    @Override
    public List<Driver> findAll() {
        return driverMapper.findAll();
    }

    @Override
    public List<Driver> findByLikeName(String name) {
        System.out.println("name ========================================= " + name);
        return driverMapper.findByNameLike("%" + name + "%");
    }


}
